import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)
// 2
/* Layout */
import Layout from '@/layout'

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'Dashboard',
        meta: { title: 'dashboard', icon: 'dashboard', affix: false }
      }
    ]
  },
  {
    path: '/userdetail',
    component: Layout,
    hidden:true,
    children: [
      {
        path: '/userdetail',
        component: () => import('@/views/dashboard/userdetail'),
        name: 'Userdetail',
        meta: { title: '个人详情', icon: 'dashboard', affix: false }
      }
    ]
  },
  {
    path: '/schedule',
    component: Layout,
    redirect: '/schedule',
    children: [
      {
        path: '/schedule',
        component: () => import('@/views/dashboard/schedule'),
        name: 'Schedule',
        meta: { title: '用户信息', icon: 'el-icon-chat-dot-round', affix: false }
      }
    ]
  },
  {
    path: '/verification',
    component: Layout,
    name: 'Verification',
    redirect: '/verification',
    alwaysShow: true,
    meta: {
      title: '验证信息',
      icon: 'el-icon-s-data',
    },
    children: [
      {
        path: 'visit',
        component: () => import('@/views/dashboard/visit'),
        name: 'Visit',
        meta: { title: '用户验证走访', icon: 'el-icon-chat-dot-round', affix: false }
      },
      {
        path: 'record',
        component: () => import('@/views/dashboard/record'),
        name: 'Record',
        meta: { title: '用户验证记录', icon: 'el-icon-chat-dot-round', affix: false }
      },
      {
        path: 'adjustCarHourse',
        component: () => import('@/views/dashboard/adjustCarHourse'),
        name: 'AdjustCarHourse',
        meta: { title: '用户购房/车的信息调整', icon: 'el-icon-chat-dot-round', affix: false }
      },
      {
        path: 'adjustCarHourseRecord',
        component: () => import('@/views/dashboard/adjustCarHourseRecord'),
        name: 'AdjustCarHourseRecord',
        meta: { title: '用户购房/车的信息调整验证记录', icon: 'el-icon-chat-dot-round', affix: false }
      }
    ]
  },
  {
    path: '/butler',
    component: Layout,
    name: 'Butler',
    redirect: '/butler',
    alwaysShow: true,
    meta: {
      title: '管家跟随',
      icon: 'el-icon-s-data',
    },
    children: [
      {
        path: 'follow',
        component: () => import('@/views/dashboard/follow'),
        name: 'Follow',
        meta: { title: '需要管家跟随用户', icon: 'el-icon-chat-dot-round', affix: false }
      },
      {
        path: 'followlist',
        component: () => import('@/views/dashboard/followList'),
        name: 'Followlist',
        meta: { title: '需要跟随用户列表', icon: 'el-icon-chat-dot-round', affix: false }
      }
    ]
  },
  {
    path: '/complaint',
    component: Layout,
    redirect: '/complaint',
    children: [
      {
        path: '/complaint',
        component: () => import('@/views/dashboard/complaint'),
        name: 'Complaint',
        meta: { title: '用户投诉', icon: 'el-icon-chat-dot-round', affix: false }
      },
      {
        path: '/handlecomplaints',
        component: () => import('@/views/dashboard/handlecomplaints'),
        name: 'Handlecomplaints',
        hidden: true,
        meta: { title: '去处理', icon: 'el-icon-chat-dot-round', affix: false }
      }
    ]
  },
  {
    path: '/userinfo',
    component: Layout,
    redirect: '/userinfo',
    children: [
      {
        path: '/userinfo',
        component: () => import('@/views/dashboard/userinfo'),
        name: 'Userinfo',
        meta: { title: '用户信息', icon: 'el-icon-chat-dot-round', affix: false }
      }
    ]
  },
  {
    path: '/cancelrecognition',
    component: Layout,
    redirect: '/cancelrecognition',
    children: [
      {
        path: '/cancelrecognition',
        component: () => import('@/views/dashboard/cancelrecognition'),
        name: 'Cancelrecognition',
        meta: { title: '用户取消认识', icon: 'el-icon-chat-dot-round', affix: false }
      }
    ]
  },
  {
    path: '/setting',
    component: Layout,
    redirect: '/setting',
    children: [
      {
        path: '/setting',
        component: () => import('@/views/dashboard/setting'),
        name: 'Setting',
        meta: { title: '设置', icon: 'el-icon-chat-dot-round', affix: false }
      }
    ]
  }
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }

]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router1111111111111
}

export default router
